package chapter5.No5_1_定时器Timer的使用.demo8;

import java.util.Date;
import java.util.Timer;

/**
 * 是因为没有抢到队列的锁，才会运行task里面的任务
 *
 * cancel()源码：
 * synchronized(queue) {
     thread.newTasksMayBeScheduled = false;
     queue.clear();
     queue.notify();  // In case queue was already empty.
  }
 * Created by Administrator on 2016/11/24.
 */
public class Main {
    public static void main(String[] args) {
        int i = 0;
        while(true) {
            i++;
            Timer t = new Timer();
            MyTask m1 = new MyTask(i);
            t.schedule(m1, new Date());
            t.cancel();
        }
    }
}
